#!/usr/bin/env python3
# _*_coding:utf-8 _*_
__author__ = "Gao"
from django import template
from crm import models
register = template.Library()


@register.simple_tag
def render_contract(enrollment_obj):
    '''渲染合同内容'''
    content = enrollment_obj.enrolled_class.contract.template.format(
        costomer=enrollment_obj.customer.name,
        price=enrollment_obj.enrolled_class.course.price,
        date='2018',
        phone=enrollment_obj.customer.phone,
        course=enrollment_obj.enrolled_class.course.name
    )
    return content


@register.simple_tag
def render_total_payment(enrollment_obj):
    '''计算学员已缴费总额'''
    payment_list = models.Payment.objects.filter(customer_id=enrollment_obj.customer_id,course_id=enrollment_obj.enrolled_class.course_id).values('amount')
    total = 0
    for payment in payment_list:
        total = payment['amount']
    return total
